<!--
 * @Description: file content
 * @Author: oooh
 * @Date: 2024-04-26 11:16:35
 * @LastEditors: hujunjie hujunjie@shudatech.cn
 * @LastEditTime: 2025-02-14 20:06:37
 * @FilePath: \Civil_Servant_Performance_PC\src\views\work-approval\assessment-grades\index.vue
-->
<template>
  <div class="app-container">
    <el-row>
      <el-col>
        <el-select v-model="queryParams.year" placeholder="选择年份" @change="handleYearChange">
          <el-option v-for="item in dict.type.biz_work_year_list" :key="item.value" :label="item.label" :value="item.value"> </el-option>
        </el-select>
      </el-col>
    </el-row>
    <div class="text-banner" style="flex-shrink: 0">
      <span>站办所绩效管理考评等次</span>
      <el-button size="mini" type="primary" circle icon="el-icon-refresh" plain @click="handleRefresh" />
    </div>
    <div class="flex justify-between" v-hasPermi="['approval:assessment-grades:submit']" style="padding-bottom:10px;">
      <div>
        <span style="font-size: 14px">批量设定：</span>
        <el-button
          size="mini"
          type="primary"
          plain
          :disabled="!selectionList.length"
          @click="handleGrade(item)"
          v-for="item in dict.type.biz_dept_year_performance_grade"
          :key="item.value"
          >{{ item.label }}</el-button
        >
      </div>
      <div>
        <el-button
          class="ml-10"
          icon="el-icon-s-claim"
          size="mini"
          type="warning"
          plain
          :disabled="!tableList.length"
          @click="handleSaveOrSubmit('save')"
          >保存</el-button
        >
      </div>
    </div>
    <div class="table">
      <el-table
        :data="tableList"
        border
        style="width: 100%"
        height="100%"
        v-loading="loading"
        @selection-change="handleSelectionChange"
        header-cell-class-name="table-header"
      >
        <el-table-column type="selection" :selectable="checkSelectable"> </el-table-column>
        <el-table-column label="序号" type="index" align="center">
          <template slot-scope="scope">
            <span>{{ scope.$index + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="deptName" label="站办所" min-width="180" align="center"> </el-table-column>
        <el-table-column prop="gradeDict" label="考评等次" align="center">
          <template slot-scope="scope">
            <el-select v-model="scope.row.gradeDict" placeholder="选择考评等次">
              <el-option v-for="item in dict.type.biz_dept_year_performance_grade" :key="item.value" :label="item.label" :value="item.value"> </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column prop="remarks" label="备注"  align="center">
          <template slot-scope="scope">
            <span class="pre-wrap align-left">{{ scope.row.remarks || '-' }}</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { list, rating as listSubmit } from '@/api/work-approval/year-grades'
import { getConfigKey } from '@/api/system/config'

export default {
  name: 'year-grades',
  dicts: ['biz_work_year_list', 'biz_dept_year_performance_grade'],
  data() {
    return {
      columns: [],
      loading: false,
      quarterOptions: [],
      tableList: [],
      work: {},
      queryParams: {
        year: ''
      },
      selectionList: []
    }
  },
  computed: {},
  watch: {},
  created() {
    this.handleYearChange(new Date().getFullYear())
  },
  methods: {
   
   
    hasPermi(permi) {
      return this.$auth.hasPermi(permi)
    },
    handleGrade(raw) {
      for (let item of this.selectionList) {
        let index = this.tableList.findIndex(tableItem => tableItem == item)
        this.$set(this.tableList[index], 'gradeDict', raw.value)
      }
    },
    // 校验表格是否可选
    checkSelectable(raw, index) {
      return !this.work.submitMark
    },
    // 表格多选
    handleSelectionChange(selection) {
      this.selectionList = selection
    },
    handleSaveOrSubmit(operation) {
      let params = this.tableList.map(item => {
        return { id: item.id, gradeDict: item.gradeDict,remarks:item.remarks }
      })
      listSubmit(params).then(res => {
        if (operation === 'submit') {
          this.$modal.msgSuccess('已提交')
        } else if (operation === 'save') {
          this.$modal.msgSuccess('已保存')
        }
        this.handleRefresh()
      })
    },
    async getList() {
      this.loading = true
      list(this.queryParams)
        .then(res => {
          this.loading = false
          this.tableList = res.data
         
        })
        .catch(err => (this.loading = false))
    },
    // 刷新
    handleRefresh() {
      this.getList()
    },
    // 年度选择
    handleYearChange(year) {
      this.queryParams.year = year
      this.getList()

    }
  }
}
</script>

<style lang="scss" scoped>
.el-input-number--medium {
  width: auto;
}
::v-deep .table-header .cell {
  white-space: pre-wrap;
}
.app-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  .table {
    flex: 1;
    overflow-y: hidden;
  }
}
</style>
